"""
@Project ：TpShopVerifyCodeOCR 
@File    ：TpShopVerifyCodeOCRTest.py
@IDE     ：PyCharm 
@Author  ：张成龙
@Date    ：2024/10/8 11:18 
@explain ：
"""
import time

import ddddocr
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from webdriver_manager.microsoft import EdgeChromiumDriverManager

driver = webdriver.Edge(EdgeChromiumDriverManager().install())

driver.get("http://192.168.56.128/Home/user/login.html")
driver.implicitly_wait(10)
driver.maximize_window()

driver.find_element(By.ID, "username").send_keys("13800138006")
driver.find_element(By.ID, "password").send_keys("123456")

verify_code_png = driver.find_element(By.ID, "verify_code_img").screenshot_as_png
ocr = ddddocr.DdddOcr()
verify_code = ocr.classification(verify_code_png)

print("验证码为："+verify_code)
time.sleep(1)
driver.find_element(By.ID, "verify_code").send_keys(verify_code)
driver.find_element(By.XPATH, "//*[@id='loginform']/div/div[6]/a").click()

driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[1]/div/ul[4]/li[4]/a").click()

time.sleep(2)

driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[2]/div/div[1]/a/span").click()
time.sleep(1)
pro = driver.find_element(By.ID, "province")

time.sleep(2)

Select(pro).select_by_visible_text("河南省")

time.sleep(3)
city = driver.find_element(By.ID, "city")

Select(city).select_by_visible_text("开封市")
time.sleep(3)
